{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "aa28107f",
   "metadata": {},
   "source": [
    "1. cat函数：字符串拼接\n",
    "2. contains函数：判断某个字符串是否包含给定字符\n",
    "3. startswith、endswith函数：判断字符串以xx开头/结尾\n",
    "4. count函数：计算给定字符在字符串中出现次数\n",
    "5. get函数：获取指定位置的字符串\n",
    "6. len函数：计算字符串长度\n",
    "7. upper、lower函数：英文大小写转换\n",
    "8. pad+side参数/center函数：在字符串左边、右边或左右两边添加给定字符\n",
    "9. Repeat函数：重复字符串几次\n",
    "10. slice_replace函数：使用给定的字符串，替换指定位置的字符\n",
    "11. Replace函数：将指定位置的字符，替换为给定的字符串\n",
    "12. Split方法+expand参数：将一列扩展为好几列\n",
    "13. strip、rstrip、lstrip函数：去除空白符、换行符\n",
    "14. Findall函数：利用正则表达式，去字符串中匹配，返回查找结果的列表\n",
    "15. Extract、extractall函数：接受正则表达式，抽取匹配的字符串（一定要加上括号）\n",
    "\n",
    "\n",
    "### 构造数据集\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6c793fc9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.048828Z",
     "start_time": "2022-01-19T15:27:59.648691Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>英文名</th>\n",
       "      <th>性别</th>\n",
       "      <th>身份证</th>\n",
       "      <th>身高</th>\n",
       "      <th>家庭住址</th>\n",
       "      <th>电话号码</th>\n",
       "      <th>收入</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>黄同学</td>\n",
       "      <td>Huang tong_xue</td>\n",
       "      <td>男</td>\n",
       "      <td>463895200003128433</td>\n",
       "      <td>mid:175_good</td>\n",
       "      <td>湖北广水</td>\n",
       "      <td>13434813546</td>\n",
       "      <td>1.1万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>黄至尊</td>\n",
       "      <td>huang zhi_zun</td>\n",
       "      <td>women</td>\n",
       "      <td>429475199912122345</td>\n",
       "      <td>low:165_bad</td>\n",
       "      <td>河南信阳</td>\n",
       "      <td>19748672895</td>\n",
       "      <td>8.5千</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>黄老邪</td>\n",
       "      <td>Huang Lao_xie</td>\n",
       "      <td>men</td>\n",
       "      <td>420934199110102311</td>\n",
       "      <td>low:159_bad</td>\n",
       "      <td>广西桂林</td>\n",
       "      <td>16728613064</td>\n",
       "      <td>0.9万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>陈大美</td>\n",
       "      <td>Chen Da_mei</td>\n",
       "      <td>女</td>\n",
       "      <td>431085200005230122</td>\n",
       "      <td>high:180_verygood</td>\n",
       "      <td>湖北孝感</td>\n",
       "      <td>14561586431</td>\n",
       "      <td>6.5千</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>孙尚香</td>\n",
       "      <td>sun shang_xiang</td>\n",
       "      <td>男</td>\n",
       "      <td>420953199509082345</td>\n",
       "      <td>low:172_bad</td>\n",
       "      <td>广东广州</td>\n",
       "      <td>19384683910</td>\n",
       "      <td>2.0万</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名              英文名     性别                 身份证                 身高  家庭住址  \\\n",
       "0   黄同学   Huang tong_xue      男  463895200003128433       mid:175_good  湖北广水   \n",
       "1   黄至尊    huang zhi_zun  women  429475199912122345        low:165_bad  河南信阳   \n",
       "2  黄老邪     Huang Lao_xie    men  420934199110102311        low:159_bad  广西桂林   \n",
       "3   陈大美      Chen Da_mei      女  431085200005230122  high:180_verygood  湖北孝感   \n",
       "4   孙尚香  sun shang_xiang      男  420953199509082345        low:172_bad  广东广州   \n",
       "\n",
       "          电话号码    收入  \n",
       "0  13434813546  1.1万  \n",
       "1  19748672895  8.5千  \n",
       "2  16728613064  0.9万  \n",
       "3  14561586431  6.5千  \n",
       "4  19384683910  2.0万  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df ={'姓名':[' 黄同学','黄至尊','黄老邪 ','陈大美','孙尚香'],\n",
    "     '英文名':['Huang tong_xue','huang zhi_zun','Huang Lao_xie','Chen Da_mei','sun shang_xiang'],\n",
    "     '性别':['男','women','men','女','男'],\n",
    "     '身份证':['463895200003128433','429475199912122345','420934199110102311','431085200005230122','420953199509082345'],\n",
    "     '身高':['mid:175_good','low:165_bad','low:159_bad','high:180_verygood','low:172_bad'],\n",
    "     '家庭住址':['湖北广水','河南信阳','广西桂林','湖北孝感','广东广州'],\n",
    "     '电话号码':['13434813546','19748672895','16728613064','14561586431','19384683910'],\n",
    "     '收入':['1.1万','8.5千','0.9万','6.5千','2.0万']}\n",
    "df = pd.DataFrame(df)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e78653f5",
   "metadata": {},
   "source": [
    "#### 1、cat函数\n",
    "\n",
    "这个函数主要用于判断字符串拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "13a79872",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.057043Z",
     "start_time": "2022-01-19T15:28:00.051427Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     黄同学---湖北广水\n",
       "1     黄至尊---河南信阳\n",
       "2    黄老邪 ---广西桂林\n",
       "3     陈大美---湖北孝感\n",
       "4     孙尚香---广东广州\n",
       "Name: 姓名, dtype: object"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"姓名\"].str.cat(df[\"家庭住址\"],sep='-'*3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "394c93d7",
   "metadata": {},
   "source": [
    "#### 2、contains函数\n",
    "\n",
    "这个函数主要用于判断某个字符串是否包含给定字符；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d3acb2b0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.064325Z",
     "start_time": "2022-01-19T15:28:00.059694Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     True\n",
       "1    False\n",
       "2     True\n",
       "3    False\n",
       "4     True\n",
       "Name: 家庭住址, dtype: bool"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"家庭住址\"].str.contains(\"广\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbaf2b88",
   "metadata": {},
   "source": [
    "#### 3. startswith、endswith函数\n",
    "\n",
    "这个函数主要用于判断某个字符串是否以...开头/结尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6ca64d97",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.072125Z",
     "start_time": "2022-01-19T15:28:00.067022Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     True\n",
       "1    False\n",
       "2     True\n",
       "3    False\n",
       "4    False\n",
       "Name: 英文名, dtype: bool"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第一个行的“ 黄伟”是以空格开头的\n",
    "df[\"姓名\"].str.startswith(\"黄\") \n",
    "df[\"英文名\"].str.endswith(\"e\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6480027a",
   "metadata": {},
   "source": [
    "#### 4. count函数\n",
    "\n",
    "这个函数主要用于计算给定字符在字符串中出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2b9f6025",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.078551Z",
     "start_time": "2022-01-19T15:28:00.073961Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    3\n",
       "1    0\n",
       "2    1\n",
       "3    1\n",
       "4    2\n",
       "Name: 电话号码, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"电话号码\"].str.count(\"3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53073c2a",
   "metadata": {},
   "source": [
    "#### 5. get函数\n",
    "\n",
    "这个函数主要用于获取指定位置的字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8ad6cbaa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.086515Z",
     "start_time": "2022-01-19T15:28:00.080334Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     mid\n",
       "1     low\n",
       "2     low\n",
       "3    high\n",
       "4     low\n",
       "Name: 身高, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"姓名\"].str.get(-1)\n",
    "df[\"身高\"].str.split(\":\")\n",
    "df[\"身高\"].str.split(\":\").str.get(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5c05d21",
   "metadata": {},
   "source": [
    "#### 6. len函数\n",
    "\n",
    "这个函数主要用于计算字符串长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c12fc0b3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.093181Z",
     "start_time": "2022-01-19T15:28:00.088395Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    5\n",
       "2    3\n",
       "3    1\n",
       "4    1\n",
       "Name: 性别, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"性别\"].str.len()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e464e89c",
   "metadata": {},
   "source": [
    "#### 7. upper、lower函数\n",
    "\n",
    "这个函数主要用于英文大小写转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "72235e5a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.102180Z",
     "start_time": "2022-01-19T15:28:00.096618Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     huang tong_xue\n",
       "1      huang zhi_zun\n",
       "2      huang lao_xie\n",
       "3        chen da_mei\n",
       "4    sun shang_xiang\n",
       "Name: 英文名, dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"英文名\"].str.upper()\n",
    "df[\"英文名\"].str.lower()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d820293b",
   "metadata": {},
   "source": [
    "#### 8. pad+side参数/center函数\n",
    "\n",
    "这个函数主要用于在字符串的左边、右边或左右两边添加给定字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "18fb3fea",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.110265Z",
     "start_time": "2022-01-19T15:28:00.104568Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    ***湖北广水***\n",
       "1    ***河南信阳***\n",
       "2    ***广西桂林***\n",
       "3    ***湖北孝感***\n",
       "4    ***广东广州***\n",
       "Name: 家庭住址, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"家庭住址\"].str.pad(10,fillchar=\"*\")      # 相当于ljust()\n",
    "df[\"家庭住址\"].str.pad(10,side=\"right\",fillchar=\"*\")    # 相当于rjust()\n",
    "df[\"家庭住址\"].str.center(10,fillchar=\"*\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aaced95e",
   "metadata": {},
   "source": [
    "#### 9.  repeat函数\n",
    "\n",
    "这个函数主要用于重复字符串几次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a4b1ae9f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.116569Z",
     "start_time": "2022-01-19T15:28:00.112087Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                男男男\n",
       "1    womenwomenwomen\n",
       "2          menmenmen\n",
       "3                女女女\n",
       "4                男男男\n",
       "Name: 性别, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"性别\"].str.repeat(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b02327a",
   "metadata": {},
   "source": [
    "#### 10.  slice_replace函数\n",
    "\n",
    "这个函数主要用于使用给定的字符串，替换指定的位置的字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2ebc3a52",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.123701Z",
     "start_time": "2022-01-19T15:28:00.118849Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1343****546\n",
       "1    1974****895\n",
       "2    1672****064\n",
       "3    1456****431\n",
       "4    1938****910\n",
       "Name: 电话号码, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"电话号码\"].str.slice_replace(4,8,\"*\"*4)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e9aadd",
   "metadata": {},
   "source": [
    "#### 11. replace函数\n",
    "\n",
    "这个函数主要用于将指定位置的字符，替换为给定的字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dcf7375f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.129686Z",
     "start_time": "2022-01-19T15:28:00.125474Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         mid-175_good\n",
       "1          low-165_bad\n",
       "2          low-159_bad\n",
       "3    high-180_verygood\n",
       "4          low-172_bad\n",
       "Name: 身高, dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"身高\"].str.replace(\":\",\"-\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5896c2be",
   "metadata": {},
   "source": [
    "这个函数还接受正则表达式，将指定位置的字符，替换为给定的字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "94048ba8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.144767Z",
     "start_time": "2022-01-19T15:28:00.139527Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-13-e0cc5e453a55>:1: FutureWarning: The default value of regex will change from True to False in a future version.\n",
      "  df[\"收入\"].str.replace(\"\\d+\\.\\d+\",\"正则\")\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0    正则万\n",
       "1    正则千\n",
       "2    正则万\n",
       "3    正则千\n",
       "4    正则万\n",
       "Name: 收入, dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"收入\"].str.replace(\"\\d+\\.\\d+\",\"正则\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "099cc2bc",
   "metadata": {},
   "source": [
    "#### 12.  split方法+expand参数\n",
    "\n",
    "这个函数主要用于将一列扩展为好几列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "024813cb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.187775Z",
     "start_time": "2022-01-19T15:28:00.179954Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         mid?????175_good\n",
       "1          low?????165_bad\n",
       "2          low?????159_bad\n",
       "3    high?????180_verygood\n",
       "4          low?????172_bad\n",
       "Name: 身高, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 普通用法\n",
    "df[\"身高\"].str.split(\":\")\n",
    "# split方法，搭配expand参数\n",
    "df[[\"身高描述\",\"final身高\"]] = df[\"身高\"].str.split(\":\",expand=True)\n",
    "df\n",
    "# split方法搭配join方法\n",
    "df[\"身高\"].str.split(\":\").str.join(\"?\"*5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05c7d026",
   "metadata": {},
   "source": [
    "#### 13. strip、rstrip、lstrip函数\n",
    "\n",
    "这个函数主要用于去除空白符、换行符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "21020d45",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.230913Z",
     "start_time": "2022-01-19T15:28:00.225335Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    3\n",
       "1    3\n",
       "2    3\n",
       "3    3\n",
       "4    3\n",
       "Name: 姓名, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"姓名\"].str.len()\n",
    "df[\"姓名\"] = df[\"姓名\"].str.strip()\n",
    "df[\"姓名\"].str.len()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fc5f780",
   "metadata": {},
   "source": [
    "#### 14. findall函数\n",
    "\n",
    "这个函数主要用于利用正则表达式，去字符串中匹配，返回查找结果的列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d6d3a83e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.270062Z",
     "start_time": "2022-01-19T15:28:00.264257Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         [mid, good]\n",
       "1          [low, bad]\n",
       "2          [low, bad]\n",
       "3    [high, verygood]\n",
       "4          [low, bad]\n",
       "Name: 身高, dtype: object"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"身高\"]\n",
    "df[\"身高\"].str.findall(\"[a-zA-Z]+\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7afd842",
   "metadata": {},
   "source": [
    "#### 15. extract、extractall函数\n",
    "\n",
    "这个函数主要用于接受正则表达式，抽取匹配的字符串(一定要加上括号)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "683f739b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-19T15:28:00.312564Z",
     "start_time": "2022-01-19T15:28:00.302382Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>mid</td>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>low</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>low</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>high</td>\n",
       "      <td>verygood</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>low</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      0         1\n",
       "0   mid      good\n",
       "1   low       bad\n",
       "2   low       bad\n",
       "3  high  verygood\n",
       "4   low       bad"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"身高\"].str.extract(\"([a-zA-Z]+)\")\n",
    "# extractall提取得到复合索引\n",
    "df[\"身高\"].str.extractall(\"([a-zA-Z]+)\")\n",
    "# extract搭配expand参数\n",
    "df[\"身高\"].str.extract(\"([a-zA-Z]+).*?([a-zA-Z]+)\",expand=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38175ae7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "nbTranslate": {
   "displayLangs": [
    "*"
   ],
   "hotkey": "alt-t",
   "langInMainMenu": true,
   "sourceLang": "en",
   "targetLang": "fr",
   "useGoogleTranslate": true
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
